<?php
namespace SSHOP;
use pocketmine\utils\Config;
use SSHOP\SSHOP as Main;
use Enchant_RPG_SHOP\Enchant_RPG_SHOP;

class File
{
	private $Main;

	public function __construct(Main $Main)
	{
		$this->Main = $Main;
		$this->Config();
	}
	
	function Config()
	{
		$dir = $this->Main->getDataFolder();
		@mkdir($dir);
		$this->Main->getLogger()->info('§e #§a开始加载插件相关配置...');
		$SHOP = new Config($dir.'SHOP.yml',Config::YAML,$this->SHOP_YML());
		$item = new Config($dir.'item.yml',Config::YAML,$this->ITEM_YML());
		if(!$item->exists('1:0'))
		{
			$item->setAll($this->ITEM_YML());
			$item->save();
		}
		$OLD_YML = $SHOP->getAll();
		$NEW_YML = $this->SHOP_YML();
		if($OLD_YML['设置']['配置文件版本'] != $NEW_YML['设置']['配置文件版本'])
		{
			$this->Main->getLogger()->warning('§e  #§4发现其他版本配置文件['.$OLD_YML['设置']['配置文件版本'].']正在进行覆盖新配置!');
			if($OLD_YML['设置']['配置文件版本'] == 'v1.1.0_1')
			{
				$SHOP->set('设置',$this->SHOP_YML()['设置']);
				$this->Main->getLogger()->warning('§e  #§4此版本因特殊原因需重置设置['.$OLD_YML['设置']['配置文件版本'].'],正在重新写入配置!');
			}
			else
			{
				$YML = array_merge($NEW_YML,$OLD_YML);
				$OLD_YML['设置']['配置文件版本'] = $NEW_YML['设置']['配置文件版本'];
				$SHOP->setAll($YML);
			}
			$SHOP->save();
			$this->Main->SHOP = new Config($dir.'SHOP.yml',Config::YAML,$this->SHOP_YML());
		}
		if(!class_exists('\\Enchant_RPG_SHOP\\Enchant_RPG_SHOP',false))
		{
			$this->Main->Enchant_RPG_SHOP = False;
			$this->Main->getLogger()->info('§e   #§c检测到服务器内未安装RPG附魔 未开启兼容模式...');
		}
		else
		{
			/*$Enchant = new Enchant_RPG_SHOP();
			$Version = $this->Main->getServer()->getPluginManager()->getPlugin('Enchant_RPG_SHOP')->getDescription()->getVersion();
			if(version_compare('2.2.0',$Version) <= 0)
			{
				$this->Main->Enchant_RPG_SHOP = $Enchant;
				$this->Main->getLogger()->info('§e   #§c检测到服务器内已安装RPG附魔 已开启兼容模式...');
			}
			else
			{
				$this->Main->Enchant_RPG_SHOP = False;
				$this->Main->getLogger()->info('§e   #§c检测到服务器内已安装RPG附魔 未开启兼容模式... [错误:版本过低!附魔至少需要V2.2.0版本!]');
			}
			*/
		}
	}

	function SHOP_YML()
	{
		return [
			'设置' => [
				'配置文件版本' => 'v1.2.1_8',
				'iconv对齐字体[推荐开启]' => True,
				'无足够空间无法开启商店' => True,
				'附近方块检测' => True,
				'商店方块ID' => 165,
				'商店中间ID' => 54,
				'物品点击地面打开商店' => 388,
				'方块方式' => '数据包',
				'数据包Y偏移' => -0.5,
				'浮空文字偏移' => ['x' => 0,'y' => 0,'z' => 0],
				'禁止创建商店世界' => ['world1','world2'],
				'游戏名最长显示' => 6,
				'商店自定义' =>
				[
					'分割线' => '§6---------------------------------------------------',
					'选中颜色' => 'b',
					'标签颜色' => 'c',
					'选中符号' => '>',
					'[1]' => 40,
					'[2]' => 70,
					'[3]' => 60,
					'[4]' => 80,
					'购买选项' => '§a购买§e[§b{物品}§e]§d{数量}§a个 [1] 需§e[§b{价格}§e]§a{货币} [2] 库存§e[§b{库存}§e]',
					'购买选中' => '§d购买§6[§a{物品}§6]§c{数量}§d个 [1] 需§6[§a{价格}§6]§d{货币} [2] 库存§6[§a{库存}§6]',
					'回收选项' => '§a回收§e[§b{物品}§e]§d{数量}§a个 [3] 获得§e[§b{价格}§e]§a{货币}',
					'回收选中' => '§d回收§6[§a{物品}§6]§c{数量}§d个 [3] 获得§6[§a{价格}§6]§d{货币}',
					'个人选项' => '§a贩卖§e[§b{物品}§e]§d{数量}§a个[1]需§e[§b{价格}§e]§a{货币} [2]§6卖家:§e[§b{卖家}§e]',
					'个人选中' => '§d贩卖§6[§a{物品}§6]§c{数量}§6个[1]需§6[§a{价格}§6]§6{货币} [2]§a卖家:§6[§b{卖家}§6]',
					'兑换选项' => '§a用§e[§b{物品1}§e]§d{数量1}§a个 [1]兑换 §e[§b{物品2}§e]§d{数量2}§a个',
					'兑换选项' => '§d用§6[§a{物品1}§6]§c{数量1}§d个 [1]兑换 §6[§a{物品2}§6]§c{数量2}§d个'
				],
				'货币名称' => [
					'金币' => '金币',
					'经验' => '经验',
					'等级' => '等级',
					'积分' => '积分',
					'附魔券' => '附魔券',
					'点券' => '点券'
				],
				'标签' => [
					'首页',
					'购买',
					'回收',
					'个人',
					'兑换',
					'药水',
					'传送',
					'拍卖',
					'强化',
					'附魔',
					'称号',
					'拍卖',
					'任务',
					'更多'
				]
			],
			'注释' =>
				['以下为上方属性可用值 =>',
				'方块方式 : 方块 或 数据包 [数据包流畅但要靠近点击而且他人看不见,方块稍远也可点击到而且可以自定义]',
                'iconv为自带函数,但有些面板未安装该组件,推荐开启!如未安装开启会导致无法切换商店,安装链接 http://www.cnblogs.com/grimm/p/5663863.html',
                '点券为 ZXDAConnector 插件 | 附魔券为 Enchant_RPG_SHOP 插件 | 积分为内置经济,购买商品或OP指令获得',
                '商店触发方式:[全部/箱子/物品/指令]',
                '标签:[购买/回收/兑换/个人/附魔/镶嵌/强化]',
                '商店自定义选项变量: {物品} {物品1} {物品2} {数量} {数量1} {数量2} {价格} {货币} {积分} {编号} {附魔} {库存} {卖家}',
                '[1/2/3/4]:代表对齐,插件会自动识别文本长度进行对齐,但由于字体一些看起来有点歪,对齐长度在上方设置'],
					'首页' => ["左边和右边有三个书架,其功能分别为
§b左标签                              右标签
上选项                              下选项
上一页             确定             下一页",
"第二页请自定义公告"],
					'购买' => [],
					'回收' => [],
					'个人' => [],
					'兑换' => [],
					'拍卖' => [],
					'强化' => [],

					'附魔' => [],
					'称号' => [],
					'拍卖' => [],
					'任务' => [],
					'药水' => [],
					'传送' => [],
					'更多' =>[]
		];
	}

function ITEM_YML()
{
    return Array(
        '1:0' => '石头',
        '2:0' => '草方块',
        '3:0' => '泥土',
        '4:0' => '圆石',
        '98:0' => '石砖',
        '98:1' => '苔石砖',
        '98:2' => '裂石砖',
        '98:3' => '錾制石砖',
        '48:0' => '苔石',
        '5:0' => '橡木木板',
        '5:1' => '云杉木板',
        '5:2' => '白桦木板',
        '5:3' => '丛林木板',
        '5:4' => '金合欢木板',
        '5:5' => '深色橡木木板',
        '45:0' => '砖块',
        '1:1' => '花岗岩',
        '1:2' => '磨制花岗岩',
        '1:3' => '闪长岩',
        '1:4' => '磨制闪长岩',
        '1:5' => '安山岩',
        '1:6' => '磨制安山岩',
        '243:0' => '灰化土',
        '110:0' => '菌丝',
        '82:0' => '粘土',
        '172:0' => '硬化粘土',
        '159:0' => '白色染色粘土',
        '159:1' => '橙色染色粘土',
        '159:2' => '品红染色粘土',
        '159:3' => '淡蓝色染色粘土',
        '159:4' => '黄色染色粘土',
        '159:5' => '黄绿色染色粘土',
        '159:6' => '粉色染色粘土',
        '159:7' => '灰色染色粘土',
        '159:8' => '淡灰色染色粘土',
        '159:9' => '青色染色粘土',
        '159:10' => '紫色染色粘土',
        '159:11' => '蓝色染色粘土',
        '159:12' => '棕色染色粘土',
        '159:13' => '绿色染色粘土',
        '159:14' => '红色染色粘土',
        '159:15' => '黑色染色粘土',
        '24:0' => '沙石',
        '24:1' => '磨制沙石',
        '24:2' => '平滑沙石',
        '12:0' => '沙子',
        '12:1' => '红沙',
        '13:0' => '沙砾',
        '17:0' => '橡木',
        '17:1' => '云杉木',
        '17:2' => '白桦木',
        '17:3' => '丛林木',
        '162:0' => '金合欢木',
        '162:1' => '深色橡木',
        '112:0' => '地狱砖块',
        '87:0' => '地狱岩',
        '88:0' => '灵魂沙',
        '7:0' => '基岩',
        '67:0' => '石楼梯',
        '53:0' => '橡木楼梯',
        '134:0' => '云杉木楼梯',
        '135:0' => '桦木楼梯',
        '136:0' => '丛林楼梯',
        '163:0' => '金合欢木楼梯',
        '164:0' => '深色橡木楼梯',
        '108:0' => '砖楼梯',
        '128:0' => '沙石楼梯',
        '109:0' => '石砖楼梯',
        '114:0' => '地狱砖楼梯',
        '156:0' => '石英楼梯',
        '44:0' => '石台阶',
        '44:3' => '圆石台阶',
        '158:0' => '橡木台阶',
        '158:1' => '云杉木台阶',
        '158:2' => '橡木台阶',
        '158:3' => '丛林木台阶',
        '158:4' => '金合欢木台阶',
        '158:5' => '深色橡木台阶',
        '44:4' => '砖台阶',
        '44:1' => '沙石台阶',
        '44:5' => '石砖台阶',
        '44:6' => '石英台阶',
        '44:7' => '地狱砖台阶',
        '155:0' => '石英块',
        '155:1' => '錾制石英块',
        '155:2' => '竖纹石英块',
        '16:0' => '煤矿石',
        '15:0' => '铁矿石',
        '14:0' => '金矿石',
        '56:0' => '钻石矿石',
        '21:0' => '青金石矿石',
        '73:0' => '红石矿石',
        '129:0' => '绿宝石矿石',
        '153:0' => '下界石英矿石',
        '49:0' => '黑曜石',
        '79:0' => '冰',
        '174:0' => '浮冰',
        '80:0' => '雪',
        '121:0' => '末地石',
        '165:0' => '粘液块',
        '139:0' => '圆石墙',
        '139:1' => '苔石墙',
        '111:0' => '睡莲',
        '41:0' => '金块',
        '42:0' => '铁块',
        '57:0' => '钻石块',
        '22:0' => '青金石块',
        '173:0' => '煤炭块',
        '133:0' => '绿宝石块',
        '152:0' => '红石块',
        '78:0' => '顶层雪',
        '20:0' => '玻璃',
        '89:0' => '萤石',
        '106:0' => '藤蔓',
        '65:0' => '梯子',
        '19:0' => '海绵',
        '102:0' => '玻璃板',
        '324:0' => '橡木门',
        '427:0' => '云杉木门',
        '428:0' => '白桦木门',
        '429:0' => '丛林木门',
        '430:0' => '金合欢木门',
        '431:0' => '深色橡木门',
        '330:0' => '铁门',
        '96:0' => '活板门',
        '167:0' => '铁活板门',
        '85:0' => '橡木栅栏',
        '85:1' => '云杉木栅栏',
        '85:2' => '白桦木栅栏',
        '85:3' => '丛林木栅栏',
        '85:4' => '金合欢木栅栏',
        '85:5' => '深色橡木栅栏',
        '113:0' => '地狱砖栅栏',
        '107:0' => '橡木栅栏门',
        '184:0' => '白桦木栅栏门',
        '183:0' => '云杉木栅栏门',
        '186:0' => '深色橡木栅栏门',
        '185:0' => '丛林木栅栏门',
        '187:0' => '金合欢木栅栏门',
        '101:0' => '铁栏杆',
        '355:0' => '床',
        '47:0' => '书架',
        '321:0' => '画',
        '389:0' => '物品展示栏',
        '58:0' => '工作台',
        '245:0' => '切石机',
        '54:0' => '箱子',
        '146:0' => '陷阱箱',
        '61:0' => '熔炉',
        '379:0' => '酿造台',
        '380:0' => '炼药锅',
        '25:0' => '音符盒',
        '120:0' => '末地传送门',
        '145:0' => '铁砧',
        '145:4' => '轻微损坏的铁砧',
        '145:8' => '严重损坏的铁砧',
        '37:0' => '蒲公英',
        '38:0' => '罂粟',
        '38:1' => '兰花',
        '38:2' => '绒球葱',
        '38:3' => '茜草花',
        '38:4' => '红色郁金香',
        '38:5' => '橙色郁金香',
        '38:6' => '白色郁金香',
        '38:7' => '粉色郁金香',
        '38:8' => '滨菊',
        '175:0' => '向日葵',
        '175:1' => '丁香',
        '175:2' => '高草丛',
        '175:3' => '大型蕨',
        '175:4' => '玫瑰丛',
        '175:5' => '牡丹',
        '39:0' => '蘑菇',
        '40:0' => '蘑菇',
        '99:14' => '蘑菇',
        '100:14' => '蘑菇块',
        '99:0' => '蘑菇',
        '99:10' => '蘑菇',
        '81:0' => '仙人掌',
        '103:0' => '西瓜',
        '86:0' => '南瓜',
        '91:0' => '南瓜灯',
        '30:0' => '蜘蛛网',
        '170:0' => '干草块',
        '31:1' => '草',
        '31:2' => '蕨',
        '32:0' => '枯死的灌木',
        '6:0' => '橡木树苗',
        '6:1' => '云杉树苗',
        '6:2' => '白桦树苗',
        '6:3' => '丛林树苗',
        '6:4' => '金合欢树苗',
        '6:5' => '深色橡木树苗',
        '18:0' => '橡树树叶',
        '18:1' => '云杉树叶',
        '18:2' => '白桦树叶',
        '18:3' => '丛林树叶',
        '161:0' => '金合欢树叶',
        '161:1' => '深色橡木树苗',
        '354:0' => '蛋糕',
        '397:0' => '骷髅头颅',
        '397:1' => '凋灵骷髅头颅',
        '397:2' => '僵尸的头',
        '397:3' => '头',
        '397:4' => '爬行者的头',
        '323:0' => '告示牌',
        '390:0' => '花盆',
        '52:0' => '刷怪箱',
        '116:0' => '附魔台',
        '35:0' => '羊毛',
        '35:8' => '淡灰色羊毛',
        '35:7' => '灰色羊毛',
        '35:15' => '黑色羊毛',
        '35:12' => '棕色羊毛',
        '35:14' => '红色羊毛',
        '35:1' => '橙色羊毛',
        '35:4' => '黄色羊毛',
        '35:5' => '黄绿色羊毛',
        '35:13' => '绿色羊毛',
        '35:9' => '青色羊毛',
        '35:3' => '淡蓝色羊毛',
        '35:11' => '蓝色羊毛',
        '35:10' => '紫色羊毛',
        '35:2' => '品红色羊毛',
        '35:6' => '粉色羊毛',
        '171:0' => '地毯',
        '171:8' => '淡灰色地毯',
        '171:7' => '灰色地毯',
        '171:15' => '黑色地毯',
        '171:2' => '品红色地毯',
        '171:14' => '红色地毯',
        '171:1' => '橙色地毯',
        '171:4' => '黄色地毯',
        '171:5' => '黄绿色地毯',
        '171:13' => '绿色地毯',
        '171:9' => '青色地毯',
        '171:3' => '淡蓝色地毯',
        '171:11' => '蓝色地毯',
        '171:10' => '紫色地毯',
        '171:6' => '粉红色地毯',
        '66:0' => '铁轨',
        '126:0' => '激活铁轨',
        '28:0' => '探测铁轨',
        '50:0' => '火把',
        '325:0' => '桶',
        '325:1' => '牛奶',
        '325:8' => '水桶',
        '325:10' => '岩浆桶',
        '46:0' => 'TNT',
        '331:0' => '红石',
        '261:0' => '弓',
        '346:0' => '钓鱼竿',
        '259:0' => '打火石',
        '359:0' => '剪刀',
        '347:0' => '钟',
        '345:0' => '指南针',
        '328:0' => '矿车',
        '333:0' => '橡木船',
        '333:1' => '杉木船',
        '333:2' => '桦木船',
        '333:3' => '木船',
        '333:4' => '相思船',
        '333:5' => '黑橡木船',
        '383:15' => '村民幼体',
        '383:10' => '鸡幼崽',
        '383:11' => '牛幼崽',
        '383:12' => '猪幼崽',
        '246:0' => '发光的黑曜石',
        '247:0' => '下界反映盒',
        '383:13' => '绵羊幼崽',
        '383:14' => '狼幼崽',
        '383:22' => '豹猫幼崽',
        '383:16' => '蘑菇幼体',
        '383:32' => '僵尸幼体',
        '383:36' => '僵尸猪人幼体',
        '383:17' => '鱿鱼幼体',
        '383:40' => '洞穴蜘蛛幼崽',
        '383:42' => '岩浆怪幼体',
        '383:41' => '妖鬼幼体',
        '383:43' => '火焰幼体',
        '268:0' => '木剑',
        '290:0' => '木锄',
        '269:0' => '木锹',
        '270:0' => '木镐',
        '271:0' => '木斧',
        '272:0' => '石剑',
        '291:0' => '石锄',
        '273:0' => '石锹',
        '274:0' => '石镐',
        '275:0' => '石斧',
        '267:0' => '铁剑',
        '292:0' => '铁锄',
        '256:0' => '铁锹',
        '257:0' => '铁镐',
        '258:0' => '铁斧',
        '276:0' => '钻石剑',
        '293:0' => '钻石锄',
        '277:0' => '钻石锹',
        '278:0' => '钻石镐',
        '279:0' => '钻石斧',
        '283:0' => '金剑',
        '294:0' => '金锄',
        '284:0' => '金锹',
        '285:0' => '金镐',
        '286:0' => '金斧',
        '298:0' => '皮革帽子',
        '299:0' => '皮革外套',
        '300:0' => '皮革裤子',
        '301:0' => '皮革靴子',
        '302:0' => '锁链头盔',
        '303:0' => '锁链胸甲',
        '304:0' => '锁链护腿',
        '305:0' => '锁链靴子',
        '306:0' => '铁头盔',
        '307:0' => '铁胸甲',
        '308:0' => '铁护腿',
        '309:0' => '铁靴子',
        '310:0' => '钻石头盔',
        '311:0' => '钻石护甲',
        '312:0' => '钻石护腿',
        '313:0' => '钻石靴子',
        '314:0' => '金头盔',
        '315:0' => '金胸甲',
        '316:0' => '金护腿',
        '317:0' => '金靴子',
        '69:0' => '拉杆',
        '123:0' => '红石灯',
        '76:0' => '红石火把',
        '72:0' => '木质压力板',
        '70:0' => '石质压力板',
        '147:0' => '测重压里板',
        '148:0' => '测重压力板',
        '143:0' => '按钮',
        '77:0' => '按钮',
        '151:0' => '阳光传感器',
        '131:0' => '绊线钩',
        '365:0' => '生鸡肉',
        '125:3' => '投掷器',
        '23:3' => '发射器',
        '332:0' => '雪球',
        '263:0' => '煤炭',
        '263:1' => '木炭',
        '264:0' => '钻石',
        '265:0' => '铁锭',
        '266:0' => '金锭',
        '388:0' => '绿宝石',
        '280:0' => '木棍',
        '281:0' => '碗',
        '287:0' => '线',
        '288:0' => '羽毛',
        '318:0' => '燧石',
        '334:0' => '皮革',
        '415:0' => '兔子皮',
        '353:0' => '糖',
        '406:0' => '下界石英',
        '339:0' => '纸',
        '360:0' => '西瓜片',
        '262:0' => '箭',
        '352:0' => '骨头',
        '338:0' => '甘蔗',
        '296:0' => '小麦',
        '295:0' => '小麦种子',
        '361:0' => '南瓜种子',
        '362:0' => '西瓜种子',
        '458:0' => '甜菜根种子',
        '260:0' => '苹果',
        '466:0' => '金苹果',
        '349:0' => '生鱼',
        '460:0' => '生鲑鱼',
        '461.0' => '小丑鱼',
        '462:0' => '河豚',
        '463:0' => '熟鲑鱼',
        '367:0' => '腐肉',
        '282:0' => '蘑菇煲',
        '297:0' => '面包',
        '319:0' => '生猪肉',
        '320:0' => '熟猪肉',
        '366:0' => '熟鸡肉',
        '363:0' => '生牛肉',
        '364:0' => '牛排',
        '391:0' => '胡萝卜',
        '392:0' => '马铃薯',
        '393:0' => '烤马铃薯',
        '394:0' => '毒马铃薯',
        '357:0' => '曲奇',
        '400:0' => '南瓜派',
        '411:0' => '生兔肉',
        '412:0' => '熟兔肉',
        '413:0' => '兔肉煲',
        '378:0' => '岩浆膏',
        '369:0' => '烈焰棒',
        '371:0' => '金粒',
        '396:0' => '金萝卜',
        '382:0' => '闪烁的西瓜',
        '414:0' => '兔子腿',
        '370:0' => '恶魂之泪',
        '341:0' => '粘液球',
        '377:0' => '烈焰粉',
        '372:0' => '地狱疣',
        '289:0' => '火药',
        '348:0' => '萤石粉',
        '37:0' => '蜘蛛眼',
        '376:0' => '发酵蛛眼',
        '384:0' => '附魔之瓶',
        '351:0' => '红玫瑰',
        '351:8' => '灰色染料',
        '351:7' => '淡灰色染料',
        '351:15' => '骨粉',
        '351:12' => '淡蓝色染料',
        '351:14' => '橙色染料',
        '351:4' => '青金石',
        '351:5' => '紫色染料',
        '351:13' => '品红色染料',
        '351:9' => '粉红色染料',
        '351:3' => '可可豆',
        '351:11' => '蒲公英黄',
        '351:10' => '黄绿色染料',
        '351:2' => '仙人掌绿',
        '351:6' => '青色染料',
        '373:6' => '夜视药水',
        '373:8' => '隐身药水',
        '373:11' => '跳跃药水'
    );
}
}